package cn.laixueit.source.config;

import cn.laixueit.source.basepo.BaseEntity;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author duxiang
 * @date 2024/2/26 13:40
 */
@Component
@Slf4j
public class MPAutoInsertConfig implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName(BaseEntity.AutoInsertField.createTime.getValue(),new Date(),metaObject);
        this.setFieldValByName(BaseEntity.AutoInsertField.updateTime.getValue(), new Date(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName(BaseEntity.AutoInsertField.updateTime.getValue(),new Date(),metaObject);
    }
}
